package com.yiya.service;

import java.util.Date;
import java.util.List;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.yiya.bean.PriceHistory;
import com.yiya.bean.SysUser;
import com.yiya.mapper.PriceHistoryMapper;
import com.yiya.model.PriceHistoryCplex;
import com.yiya.model.PriceHistoryCplexModel;

@Service("priceHistoryService")
public class PriceHistoryService {
	@SuppressWarnings("unused")
	private final static Logger log = Logger.getLogger(PriceHistoryService.class);

	@Autowired
	private PriceHistoryMapper priceHistoryMapper;
	
	public List<PriceHistoryCplex> queryByList(PriceHistoryCplexModel bean) {
		Integer rowCount = queryByCount(bean);
		bean.getPager().setRowCount(rowCount);
		List<PriceHistoryCplex> priceHistoryCplexs = priceHistoryMapper.selectByModel(bean);
		return priceHistoryCplexs;
	}
	
	public int queryByCount(PriceHistoryCplexModel bean){
		return priceHistoryMapper.countByModel(bean);
	}
	
	public int add(PriceHistory bean){
		return priceHistoryMapper.insert(bean);
	}
	
	public int Update(PriceHistory bean){
		return priceHistoryMapper.updateByPrimaryKeySelective(bean);
	}
	
	public PriceHistory queryById(Integer id){
		return priceHistoryMapper.selectByPrimaryKey(id);
	}
	
	public void delete(Integer[] ids,SysUser user){
		Date nowTime = new Date();
		for(Integer id:ids){
			PriceHistory bean = priceHistoryMapper.selectByPrimaryKey(id);
			bean.setUpdateBy(user.getId());
			bean.setUpdateTime(nowTime);
			bean.setDelFlag(1);
			priceHistoryMapper.updateByPrimaryKeySelective(bean);
		}
	}
}
